/******************************************************************************

	COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2010.

	This file is part of Maxsi Engine.

	Maxsi Engine is free software: you can redistribute it and/or modify it
	under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or (at your
	option) any later version.

	Maxsi engine is distributed in the hope that it will be useful, but WITHOUT
	ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
	FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
	for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with Maxsi Engine. If not, see <http://www.gnu.org/licenses/>.

	MaxsiEngine.dll
	A general purpose C++ library for the Maxsi Technology Project.

	MaxsiIOBin2Hex.cpp
	Takes binary data as input and outputs hex, or the other way around.

******************************************************************************/

#include "MaxsiEngine.h"

#ifdef Maxsi_Support_MaxsiIO

BeginMaxsiNamespace

//=============================================================================
//	MaxsiIOBin2Hex
//
//		NI: Accepts binary data and outputs it on IO in hex form.
//		NO: Outputs the binary data from II in hex form.
//		RI: Accepts hex data and outputs it on OO in binary form.
//		RO: Outputs the hex data from OI in binary form.
//		
//=============================================================================

MaxsiIOBin2Hex::MaxsiIOBin2Hex()
{
	
}

MaxsiIOBin2Hex::~MaxsiIOBin2Hex()
{
	
}

FLAGSL32 MaxsiIOBin2Hex::GetCapabilities()
{
	return ( MAXSI_IO_SUPPORTS_VIRTUAL_SOCKETS | MAXSI_IO_SUPPORTS_NON_BLOCKING | MAXSI_IO_SUPPORTS_NORMAL_MODE | MAXSI_IO_SUPPORTS_REVERSE_MODE );
}


MaxsiError CreateBuffers()
{
	return MAXSI_ERROR_SUCCESS;
}

MaxsiError DeleteBuffers()
{
	return MAXSI_ERROR_SUCCESS;
}

MaxsiError MaxsiIOBin2Hex::CreateBuffers(MaxsiIOSocket* Socket)
{
	if ( Socket == NULL ) { return MAXSI_ERROR_INVALID_INPUT; }

	if ( Socket == &NI && NIBuf == NULL ) { NIBuf = CreateBuffer(8192); if ( NIBuf == NULL ) { return MAXSI_ERROR_MEM_ALLOC_FAIL; } } else
	if ( Socket == &RI && RIBuf == NULL ) { RIBuf = CreateBuffer(8192); if ( RIBuf == NULL ) { return MAXSI_ERROR_MEM_ALLOC_FAIL; } } else
	if ( Socket == &NO && NOBuf == NULL ) { NOBuf = CreateBuffer(16384); if ( NOBuf == NULL ) { return MAXSI_ERROR_MEM_ALLOC_FAIL; } } else
	if ( Socket == &RO && ROBuf == NULL ) { ROBuf = CreateBuffer(16384); if ( ROBuf == NULL ) { return MAXSI_ERROR_MEM_ALLOC_FAIL; } }

	return MAXSI_ERROR_SUCCESS;
}

MaxsiError MaxsiIOBin2Hex::DeleteBuffers(MaxsiIOSocket* Socket)
{
	if ( Socket == NULL ) { return MAXSI_ERROR_INVALID_INPUT; }

	if ( Socket == &NI && NIBuf != NULL ) { DeleteBuffer(NIBuf); NIBuf = NULL; } else
	if ( Socket == &RI && RIBuf != NULL ) { DeleteBuffer(RIBuf); RIBuf = NULL; } else
	if ( Socket == &NO && NOBuf != NULL ) { DeleteBuffer(NOBuf); NOBuf = NULL; } else
	if ( Socket == &RO && ROBuf != NULL ) { DeleteBuffer(ROBuf); ROBuf = NULL; }

	return MAXSI_ERROR_SUCCESS;
}

MaxsiError MaxsiIOBin2Hex::OnThink()
{
	return MAXSI_ERROR_SUCCESS;
}

EndMaxsiNamespace

#endif

